<?php 
$this->lang->load('admin_ad', $this->session->admin_language);
$this->load->view('admin/layout/head', array('title'=>$this->lang->line('ad')), FALSE);
?>

<div id="container">
	
	<form class="form-inline" id="search-form" method="GET" action="/admin/ad">
	  <div class="form-group">
	  	<select name="type" class="form-control">
	  		<option value=""><?php echo $this->lang->line('category') ?></option>
	  		<?php foreach($types as $k=>$v): ?>
	  		<option value="<?php echo $k?>"><?php echo $v[$this->session->admin_language] ?></option>
	  		<?php endforeach; ?>
	  	</select>
	  </div>
	  <a href="javascript:;" class="btn btn-info search-btn"><?php echo $this->lang->line('search') ?></a>
	  <a href="/admin/ad/add" class="btn btn-default add-btn"><span class="glyphicon glyphicon-plus"></span> <?php echo $this->lang->line('add') ?></a>
	</form>
	
	<div class="table-container mt-10">
		<table class="table table-bordered table-striped table-hover scroll-table">
			<thead >
				<tr>
					<th width="240" class="text-center"><?php echo $this->lang->line('pic') ?></th>
					<th width="100" class="text-center"><?php echo $this->lang->line('category') ?></th>
					<th width="60" class="text-center"><?php echo $this->lang->line('sort') ?></th>
					<th width="100" class="text-center"><?php echo $this->lang->line('create_time') ?></th>
					<th width="80" class="text-center"><?php echo $this->lang->line('actions') ?></th>
				</tr>
			</thead>
			<tbody class="text-center">
				<?php foreach($ads as $q): ?>
				<tr id='tr-<?php echo $q['id']?>'>
					<td class="text-left"><img src="<?php echo $q['image'] ?>" style="max-width: 600px; max-height: 100px" /></td>
					<td ><?php echo $types[$q['type']][$this->session->admin_language] ?></td>
					<td><?php echo $q['sort'] ?></td>
					<td><?php echo date('Y-m-d H:i',$q['create_time']) ?></td>
					<td>
						<a href="/admin/ad/edit/<?php echo $q['id'] ?>" class="modify-btn"><?php echo $this->lang->line('edit') ?></a> | 
						<a href="javascript:;" class="del-btn" ad_id="<?php echo $q['id'] ?>"><?php echo $this->lang->line('delete') ?></a>			
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
			
		</table>
	</div>
</div>


<?php 
$this->load->view('admin/layout/footer');
?>

<script type="text/javascript">
	$(function(){
		$('.del-btn').on('click',function(){
			var ad_id = $(this).attr('ad_id');
			confirm('<?php echo $this->lang->line('delete_confirm') ?>',function(e){
				if(e.index == 1){
					Toast.loading();
					$.post('/admin/ad/delete', {id: ad_id}, function(data, textStatus, xhr) {
						Toast.destory();
						Toast.success('<?php echo $this->lang->line('delete_success') ?>',function(){
							window.location.reload();
						})
					});
				}
			})
		});
		
		$('.search-btn').on('click',function(){
			$('#search-form').submit();
		})

		var hash = window.location.hash;
		if(hash){
			$(hash).css('background-color','#ccc');
		}
	})
</script>















